﻿using System.Linq;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.WeChatMall.Domain.Entitys.Orders;
using ZilLion.Service.WeChatMall.Domain.Repositorys.Interface.Order;

namespace ZilLion.Service.WeChatMall.Domain.Repositorys.Order
{
    public class OrderSendRepository : SqlServerRespository<OrderDeliverySendEntity>,
        IOrderSendRepository
    {
        public OrderSendRepository()
        {
            Context = new WechatMallContext();
        }

        public OrderDeliverySendEntity GetOrderSendDeliveryInfo(string sno)
        {
            var sql =
                $@"SELECT  ddlsh AS OrderSno,
                ddjfsj AS DeliveryTime,
                ddjwd AS Location,
                ddcscode AS Adcode,
                dddbdz AS GpsAddress,
                ddshdz AS DetailAddress,
                ddshr AS Receiver,
                ddshrxb AS Sex,
                ddshrdh AS ReceiverTel,
                ddbz AS ReceiverDesc
                FROM    weiscddjfxxpst                
                where ddlsh=@sno";
            return GetList(sql, new {sno}).FirstOrDefault();
        }


        public void SaveOrderSendDelivery(OrderDeliverySendEntity entity, OrderMainInfoDto orderMain,
            UnitOfWork unit = null)
        {
            DapperHelper.Execute("delete from weiscddjfxxpst where ddlsh=@sno", Context, unit,
                new {sno = orderMain.Sno});
            Add(entity, unit);
        }
    }
}